<?php
// create custom plugin settings menu
add_action('admin_menu', 'featupdates_create_menu');

function featupdates_create_menu() {

	//create new dashboard menu page
	add_dashboard_page('Features & Updates', 'Features & Updates', 'administrator', __FILE__, 'featupdates_settings_page', 'favicon.ico', '4');
        
	//call register settings function
	add_action( 'admin_init', 'register_featupdatesettings' );
}

function register_featupdatesettings() {
	//register our settings
	register_setting( 'featupdate-settings-group', 'featupdate_tracking_code' );
}

function featupdates_settings_page() {
?>

<div class="wrap">
<h2>Silicon Solar Website Features &amp; Updates Log</h2>

<?php

   $args = array('page_id' => 28537);
   $errorlog = new WP_Query($args);

   if($errorlog->have_posts()) : 
      while($errorlog->have_posts()) : 
         $errorlog->the_post();
?>

    <?php if (get_field('featupdate')) { ?>
        <table width="85%" cell-spacing="0px" cell-padding="0px" border="0px">
            <tr>
                <td style="width:10%;height:40px;line-height:40px;background:#f2f2f2;font-size:15px;font-weight:bold;">Date</td>
                <td style="width:20%;height:40px;line-height:40px;background:#f2f2f2;font-size:15px;font-weight:bold;">Error</td>
                <td style="width:50%;height:40px;line-height:40px;background:#f2f2f2;font-size:15px;font-weight:bold;">Notes</td>
                <td style="width:20%;height:40px;line-height:40px;background:#f2f2f2;font-size:15px;font-weight:bold;text-align:right;padding-right:20px;">Status</td>
            </tr>
        <?php while(has_sub_field('featupdate')) : ?>
            <tr>
                <td style="vertical-align:top;padding-top:10px;padding-bottom:10px;border-bottom:#cccccc 1px solid;padding-left:10px;padding-right:20px;"><?php the_sub_field('featupdate_date'); ?></td>
                <td style="vertical-align:top;padding-top:10px;padding-bottom:10px;border-bottom:#cccccc 1px solid;padding-right:20px;"><?php the_sub_field('featupdate_title'); ?></td>
                <td style="vertical-align:top;padding-top:10px;padding-bottom:10px;border-bottom:#cccccc 1px solid;padding-right:20px;"><?php the_sub_field('featupdate_notes'); ?></td>
                <td style="vertical-align:top;padding-top:10px;padding-bottom:10px;border-bottom:#cccccc 1px solid;padding-left:10px;padding-right:20px;text-align:right;">
                    <?php if(get_sub_field('featupdate_link') != '') { ?>
                        <a href="http://www.siliconsolar.com/<?php the_sub_field('featupdate_link'); ?>">View How-To Guide</a>
                    <?php } else { ?>
                        No How-To Guide Exists
                    <?php } ?>
                </td>
            </tr>
        <?php endwhile; ?>
        </table>
    <?php } ?>

<?php
      endwhile;
   else: 
?>

      <p>Oops, there are no errors listed</p>

<?php
   endif;
?>

</div>
<?php } ?>